package top.jolyoulu.business.web.controller;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.jolyoulu.business.web.config.KetRuleConfig;
import top.jolyoulu.modules.redismodule.lock.DefKetRule;
import top.jolyoulu.modules.redismodule.lock.ReqRedisLock;
import top.jolyoulu.modules.redismodule.utils.RedisUtils;
import top.jolyoulu.webcommon.entity.ResultInfo;

import java.util.concurrent.TimeUnit;

/**
 * @Author LuZhouJin
 * @Date 2023/5/4
 * redis-module 测试
 */
@RestController
@RequestMapping("/test/redis")
public class TestRedisController {

    @Autowired
    private RedisUtils redisUtils;

    //测试redis读写数据功能
    @PostMapping("/set/{key}")
    public ResultInfo<JSONObject> set(@PathVariable("key") String key, @RequestBody JSONObject jsonObject) {
        redisUtils.set(key, jsonObject);
        return ResultInfo.success(jsonObject);
    }

    //测试redis读写数据功能
    @GetMapping("/get/{key}")
    public ResultInfo<Object> get(@PathVariable("key") String key) {
        return ResultInfo.success(redisUtils.get(key));
    }

    //测试redis分布式锁
    @ReqRedisLock(ruleType = DefKetRule.class, arg = "wefwefew",timeOut = 10,timeUnit = TimeUnit.HOURS)
    @GetMapping("/lock")
    public ResultInfo<Object> lock() {
        return ResultInfo.success();
    }

}
